package wangwenjun.phase2.concurrencypattern.eventbus.google.demo05;

import com.google.common.eventbus.EventBus;
import lombok.extern.slf4j.Slf4j;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import util.ThreadUtil;

/**
 * @author ChangLiang
 * @date 2020/6/19
 */
@Slf4j
public class AppTest {

    @Test
    @DisplayName("test EventExceptionHandler")
    public void test(){
        final EventBus eventBus = new EventBus((e, c) -> {
            log.error(ThreadUtil.exceptionToString(e));
            log.error("event:{} eventBus:{} subscriber:{} method:{}",
                    c.getEvent(),
                    c.getEventBus(),
                    c.getSubscriber().getClass().getSimpleName(),
                    c.getSubscriberMethod().getName());
        });
        eventBus.register(new ExceptionListener());
        String itemId = "1";
        eventBus.post(itemId);
        log.info("post the item id:{}",itemId);
    }
}
